#pragma once

#ifndef ACTUATOR_H
#define ACTUATOR_H

#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <filesystem>
#include <Windows.h>

#include "../MyDBMSNamespace.h"
#include "SQLDTO/Complier2Actuator.h"

_MY_DBMS_NAMESPACE_BEGIN
class Actuator
{
private:
	myDBMS::Complier2Actuator* com2actDTO;
	std::unordered_set<std::string> all_available_dbs;
	std::unordered_set<std::string> all_user_dbs;
	std::filesystem::path root_path;
	std::string user_name;
	std::string user_account;
	std::string user_password;
	std::string cur_using_db;
	std::string show_type;
	std::unordered_map<std::string, std::string> result_to_print;
public:
	Actuator();
	Actuator(myDBMS::Complier2Actuator* com2actDTO);
	~Actuator();
	void reGetDTO(myDBMS::Complier2Actuator* com2actDTO);
	void execute();
	void printExecuteResult();
private:
	void initDir();
	void getAllDbs();
	std::vector<std::string> split(const std::string& line, char ch = ',');
	std::string join(std::unordered_map<std::string, std::string>& datas, char ch = ',');
	std::string join(std::vector<std::string>& datas, char ch = ',');
private:
	void CreateUser();
	void DeleteUser();
	void Connect();
	void Use();
	void Show();
	void CreateDatabase();
	void DeleteDatabase();
	void CreateTable();
	void DeleteTable();
	void InsertValue();
	void DeleteRecord();
	void Select();
};
_MY_DBMS_NAMESPACE_END

#endif
